package work.xiaohong.jijin.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import work.xiaohong.jijin.entity.HttpResult;;

public class JijinHttpUtil {

    public static HttpResult sendGetReq(String url) throws Exception {

        String body= HttpUtil.get(url);

//        System.out.println("获取到响应：" + body);
        HttpResult httpResult = null;
        try {
            String result = body.substring(body.indexOf("(")+1,body.lastIndexOf(")"));
            httpResult = JSON.parseObject(result, HttpResult.class);
        }catch (Exception e){
            e.printStackTrace();
        }

        return httpResult;

    }

    public static void main(String[] args) {
        String url = "http://fundgz.1234567.com.cn/js/004753.js?rt=1615788646293";
//        String url = "http://api.money.126.net/data/feed/008714,money.api?callback=_ntes_quote_callback11416858";
        try {
            HttpResult httpResult = sendGetReq (url);
            System.out.println(httpResult);
        } catch (Exception e) {
            e.printStackTrace ( );
        }
    }

}